import React from 'react'
import logo from '../../assets/logo.jpg'
import styles from './index.module.less'
import { Form, Button, Input, Toast } from 'react-vant'
import toast from 'react-hot-toast'
import { useNavigate } from 'react-router-dom'
import axios from '../../api'
export default function register() {
    const navigate = useNavigate()
    const [form] = Form.useForm()
    const onFinish = async values => {
        const res = await axios.post('/user/register', values)
        toast.success(res.msg)
        setTimeout(() => {
            navigate(`/login`,{state:{username:values.username,password:values.password}})
        }, 1000)
    }
    return (
        <div className={styles.login}>
            <h1 className={styles.title}>注册</h1>
            <div className={styles['title-wrapper']}>
                <div className={styles.avatar}>
                    <img src={logo} alt="" />
                </div>
                <Form
                    form={form}
                    onFinish={onFinish}
                    footer={
                        <div style={{ margin: '16px 16px 0' }}>
                            <Button round nativeType='submit' type='primary' block>
                                注册
                            </Button>
                        </div>
                    }
                >
                    <Form.Item
                        tooltip={{
                            message:
                                'A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself.',
                        }}
                        intro='确保这是唯一的用户名'
                        rules={[{ required: true, message: '请填写用户名' }]}
                        name='username'
                        label='用户名'
                        labelWidth='50px'
                    >
                        <Input placeholder='请输入用户名' />
                    </Form.Item>
                    <Form.Item
                        rules={[{ required: true, message: '请填写昵称' }]}
                        name='nickname'
                        label='昵称'
                        labelWidth='50px'
                    >
                        <Input placeholder='请输入昵称' />
                    </Form.Item>
                    <Form.Item
                        rules={[{ required: true, message: '请填写密码' }]}
                        name='password'
                        label='密码'
                        labelWidth='50px'
                    >
                        <Input placeholder='请输入密码' />
                    </Form.Item>
                </Form>
            </div>
        </div>
    )
}

